perm filename A32.TEX[106,PHY] blob
sn#807730 filedate 1985-09-20 generic text, type C, neo UTF8
COMMENT ā VALID 00002 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 \magnification\magstephalf
C00012 ENDMK
Cā;
\magnification\magstephalf
\input macro.tex
\def\today{\ifcase\month\or
January\or February\or March\or April\or May\or June\or
July\or August\or September\or October\or November\or December\fi
\space\number\day, \number\year}
\baselineskip 14pt
\rm
\line{\sevenrm a32.tex[106,phy] \today\hfill}
\bigskip
\line{\bf Records.\hfill}
\bigskip
In the pre-computer age, a small company (say five people) might have
survived keeping its written payroll information as separate items of
information, each possibly on its own sheet of paper:
{\obeylines\smallskip
\qquad\qquad I promised Barney a raise to \$1.05 in May.
\qquad\qquad Paid Jonesey early this month.
\qquad\qquad Johnson's Social Security paid up for year.
\qquad\qquad What is Rodriguez's SS\#?
\smallskip}
\noindent
but, obviously, a larger organization would require systematic record
keeping to avoid catastrophe. It would have several {\sl forms\/}, one
of which might be called an employee payroll form, like
\medskip
\vbox{\offinterlineskip
\halign{\qquad\qquad\qquad\hbox to 250pt{#\hfil}\cr
NAME\cr
\phantom{NAME}\hrulefill\cr
\noalign{\medskip}
SOCIAL SECURITY NUMBER\cr
\phantom{SOCIAL SECURITY NUMBER}\hrulefill\cr
\noalign{\medskip}
PAY RATE\cr
\phantom{PAY RATE}\hrulefill\cr}}
\smallskip
\noindent
By filling out one of these forms, it would create a {\sl record\/}
for each employee.
\medskip
\vbox{\offinterlineskip
\halign{\qquad\qquad\qquad\hbox to 250pt{#\hfil}\cr
NAME\qquad {\tt JOHN SMITH}\cr
\phantom{NAME}\hrulefill\cr
\noalign{\medskip}
SOCIAL SECURITY NUMBER\qquad {\tt 413-24-1658}\cr
\phantom{SOCIAL SECURITY NUMBER}\hrulefill\cr
\noalign{\medskip}
PAY RATE\qquad {\tt \$1.00}\cr
\phantom{PAY RATE}\hrulefill\cr}}
\smallskip
\noindent
The records of a given kind (all using the same form) would be kept in
designated places, probably in a {\sl file\/}. That is to say, their location
is specified by a simple piece of information:
\halign{\qquad\qquad\lft{#}\cr
``Miss Jones, let me see the payroll file.''\cr}
\smallskip\noindent
and they come in a definite sequence, which may be specified by some algorithm.
\halign{\qquad\qquad\lft{#}\cr
``Let's keep the payroll file sorted by SSN instead of hiring date,\cr
\phantom{``}it will make it easier to find a given record in it.''\cr}
A company would have a set of algorithms for processing
either individual records
(a~pay raise, say) or whole files of records (weekly pay checks); these
algorithms would depend on the records being in the correct forms, locatable
in the files, and possibly having correct relations among the records
(sorted by SSN, for example).
Pascal has types and operations designed for carrying out algorithms on
the computer equivalents of forms and records. The forms are called
{\sl record types\/}, and the records are, understandably, called {\sl records\/}.
\vfill\eject
A Record Type in Pascal is of the form
\halign{\qquad\qquad\lft{#}\cr
{\tt RECORD}(\qquad type declarations\qquad)\cr}
\noindent
; for example
\halign{\qquad\qquad\lft{#}\cr
{\tt RECORD(EMPNAME:STRING(30); SSN:INTEGER; PAYRATE:REAL)}\cr}
This does not mean that there is a single variable called {\tt EMPNAME}. There
may be no {\tt STRING(30)} variable, or there may be thousands in the
program. It says that every record of the above type (which must get a name)
contains a piece of information called the {\tt EMPNAME} of that record,
which can be treated like a {\tt STRING(30)} variable (fetched and assigned).
As yet, this record type has been described, but not given a name. In a
program which has several record types, when we want to create a new
record (say for a newly hired employee), we need a name for this record
type. Rather than write it all out
\smallskip
\halign{\qquad\qquad\lft{\tt #}\cr
VAR PRESIDENT:RECORD(EMPNAME:STRING(30); SSN:INTEGER; PAYRATE:REAL);\cr
VAR DISHWASHERS:ARRAY[1..100] OF\cr
\qquad RECORD(EMPNAME:STRING(30); SSN:INTEGER; PAYRATE:REAL);\cr}
\smallskip
\noindent
(which gives no way to apply a single procedure to the president and the
dishwasher [?])
we define a type name
\halign{\qquad\qquad\lft{#}\cr
{\tt TYPE EMPREC = RECORD(EMPNAME:STRING(30); SSN:INTEGER; PAYRATE:REAL)}\cr}
\noindent
and then declare variables to be of the named type:
\smallskip
\halign{\qquad\qquad\lft{\tt #}\cr
VAR PRESIDENT:EMPREC;\cr
\qquad $\vdots$\cr
VAR DISHWASHERS:ARRAY[1..100] OF EMPREC;\cr}
\smallskip
Given the name of a specific record, like {\tt PRESIDENT} or
{\tt DISHWASHER[13]}, we can refer to any of the variables it contains
by `{\tt .}' and the field name;
\halign{\qquad\qquad\lft{\tt #}\cr
RECORDNAME.FIELDNAME\cr}
\noindent
is a variable name, of the same type as the field name.
\smallskip
\halign{\qquad\qquad\lft{\tt #}\cr
WRITE(PRESIDENT.NAME);\cr
PRESIDENT.NAME:='HAROLD STASSEN\ \ \ ';\cr
IF PRESIDENT.NAME[1]='R' THEN\cr
DISHWASHER[13].PAYRATE:=MINWAGE;\cr}
\bigskip
\noindent
[RWF: Following is an outline.]
Above has records analogous to permanent books of forms, waiting to be
filled in. Can also do something analogous to printing a new copy of
the form whenever one is needed, with a unique marker, like a serial
number, on it, saved in a file room, where locatable by serial number.
To avoid losing track, the serial number must be recorded elsewhere,
maybe in a variable, maybe as a field in another record of same
or different type.]
\bigskip
\parindent0pt
\copyright 1984 Robert W. Floyd
First draft September 10, 1984
\bye